package o;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Locale;
import o.ckh.a;
import o.ckh.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public abstract class dvr {
    private static int ˎ;

    static class b extends SafeBroadcastReceiver {
        private final WeakReference<Activity> ˊ;

        public b(Activity activity) {
            this.ˊ = new WeakReference(activity);
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) {
                NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra("networkInfo");
                if (networkInfo != null && State.CONNECTED == networkInfo.getState()) {
                    int ॱ = dvt.ॱ(context);
                    if (ॱ == 0 || dvr.ˎ == ॱ) {
                        Logger.ˎ("DownloadDialogUtils", "Keep current download dialog");
                        return;
                    }
                    Logger.ˎ("DownloadDialogUtils", "network has changed,close the download dialog, new net type=" + ॱ);
                    Activity activity = (Activity) this.ˊ.get();
                    if (activity != null) {
                        activity.finish();
                    }
                }
            }
        }
    }

    static class d implements e {
        private BroadcastReceiver ˏ;

        public void ॱ(Activity activity) {
            this.ˏ = new b(activity);
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            activity.registerReceiver(this.ˏ, intentFilter);
        }

        public void ˋ(Activity activity) {
            if (this.ˏ != null) {
                activity.unregisterReceiver(this.ˏ);
            }
        }
    }

    private static View ˋ(Context context, String str, boolean z) {
        View inflate = LayoutInflater.from(context).inflate(h.ꜝ, null);
        ((TextView) inflate.findViewById(j.ॱꞋ)).setText(str);
        CheckBox checkBox = (CheckBox) inflate.findViewById(j.ᐝՙ);
        if (z) {
            checkBox.setVisibility(0);
            checkBox.setText(n.ʿˊ);
        } else {
            checkBox.setVisibility(8);
            ((TextView) inflate.findViewById(j.ॱⵗ)).setVisibility(8);
        }
        return inflate;
    }

    private static View ॱ(Context context, String str, boolean z) {
        View inflate = LayoutInflater.from(context).inflate(h.ˊᶥ, null);
        ((TextView) inflate.findViewById(j.ˋˡ)).setText(str);
        CheckBox checkBox = (CheckBox) inflate.findViewById(j.ˋˮ);
        if (z) {
            checkBox.setVisibility(0);
            checkBox.setText(n.ʿˊ);
        } else {
            checkBox.setVisibility(8);
        }
        return inflate;
    }

    public static long ˋ(dwl o_dwl) {
        long ˏ = dkb.ˏ(o_dwl.ˊ()) - o_dwl.ˊ().ˋˊ();
        List<SessionDownloadTask> ᐝˋ = o_dwl.ˊ().ᐝˋ();
        if (ᐝˋ == null) {
            return ˏ;
        }
        long j = ˏ;
        for (SessionDownloadTask sessionDownloadTask : ᐝˋ) {
            j = (dkb.ˏ(sessionDownloadTask) - sessionDownloadTask.ˋˊ()) + j;
        }
        return j;
    }

    public static long ˏ(List<SessionDownloadTask> list) {
        long j = 0;
        for (SessionDownloadTask sessionDownloadTask : list) {
            j = (dkb.ˏ(sessionDownloadTask) - sessionDownloadTask.ˋˊ()) + j;
        }
        return j;
    }

    public static long ॱ(List<ApkUpgradeInfo> list) {
        long j = 0;
        for (ApkUpgradeInfo apkUpgradeInfo : list) {
            long ʼ;
            if (apkUpgradeInfo.ʼ() > 0) {
                ʼ = apkUpgradeInfo.ʼ() + j;
            } else {
                ʼ = apkUpgradeInfo.ʻॱ() + j;
            }
            j = ʼ;
        }
        return j;
    }

    public static boolean ˏ(Context context, boolean z) {
        boolean ॱॱ = doo.ॱॱ(context);
        boolean z2 = ॱॱ && doo.ᐝ(context);
        boolean ʻ = doo.ʻ(context);
        int ˋ = ehb.ˏ().ˋ();
        boolean ˎ = ehb.ˏ().ˎ();
        if (z) {
            Logger.ˎ("DownloadDialogUtils", "isWifiConnection=" + ॱॱ + ", isMeteredWifi=" + z2 + ", isMobileConnection=" + ʻ + ", MobileDataDownloadStatus=" + ˋ + ", isWifiHotspotDownloadEnable=" + ˎ + ", NetworkType=" + doo.ˎ(context));
        }
        if (z2 && !ˎ) {
            return false;
        }
        if (!ʻ || ˋ == 0) {
            return true;
        }
        return false;
    }

    public static boolean ˏ(Context context) {
        int ˋ = ehb.ˏ().ˋ();
        if (doo.ʻ(context) && ˋ == 1) {
            return true;
        }
        return false;
    }

    public static boolean ˋ(Context context) {
        boolean z = doo.ॱॱ(context) && doo.ᐝ(context);
        boolean ˎ = ehb.ˏ().ˎ();
        if (!z || ˎ) {
            return false;
        }
        return true;
    }

    public static boolean ॱ(Context context) {
        int ˋ = ehb.ˏ().ˋ();
        if (doo.ʻ(context) && ˋ == 2) {
            return true;
        }
        return false;
    }

    public static String ˊ(Context context) {
        Object obj = (doo.ॱॱ(context) && doo.ᐝ(context)) ? 1 : null;
        boolean ʻ = doo.ʻ(context);
        if (obj != null) {
            return NetWorkUtil.rebuildWifiKey(context.getResources().getString(n.ˏﹺ));
        }
        if (ʻ) {
            return context.getResources().getString(n.ﹳᐝ);
        }
        Logger.e("DownloadDialogUtils", "It will bot be here");
        return null;
    }

    private static String ॱ(Context context, long j) {
        int i = (doo.ॱॱ(context) && doo.ᐝ(context)) ? 1 : 0;
        if (doo.ʻ(context)) {
            return String.format(Locale.ENGLISH, context.getString(n.ﹶॱ), new Object[]{epw.ˊ(j)});
        } else if (i != 0) {
            return NetWorkUtil.rebuildWifiKey(String.format(Locale.ENGLISH, context.getString(n.ˡॱ), new Object[]{epw.ˊ(j)}));
        } else {
            Logger.e("DownloadDialogUtils", "It will not be here");
            return null;
        }
    }

    public static void ˋ(Context context, long j, a aVar, OnDismissListener onDismissListener) {
        ॱ(context, j, aVar, onDismissListener, true);
    }

    public static void ॱ(Context context, long j, a aVar, OnDismissListener onDismissListener, boolean z) {
        ˎ = 1;
        View ˋ = ˋ(context, ॱ(context, j), z);
        new DialogActivity.a(context, "MobileDataDownloadDialog").ˎ(ˋ, null).ˋ(-1, n.ʼʻ).ˋ(-2, NetWorkUtil.getWifiResId(context, n.ʼʼ)).ˏ(aVar).ˋ(onDismissListener).ॱ(new d()).ˎ();
    }

    public static void ˏ(Context context, long j, a aVar, OnDismissListener onDismissListener, e eVar, OnKeyListener onKeyListener) {
        ˎ = 1;
        View ˋ = ˋ(context, ॱ(context, j), true);
        new DialogActivity.a(context, "MobileDataDownloadDialog").ˎ(ˋ, null).ˋ(-1, n.ʼʻ).ˋ(-2, NetWorkUtil.getWifiResId(context, n.ʼʼ)).ˏ(aVar).ˋ(onDismissListener).ॱ(eVar).ˏ(onKeyListener).ˎ();
    }

    public static void ˏ(Context context, long j, a aVar, OnDismissListener onDismissListener) {
        ˎ(context, j, aVar, onDismissListener, true);
    }

    public static void ˎ(Context context, long j, a aVar, OnDismissListener onDismissListener, boolean z) {
        ˎ = 2;
        View ॱ = ॱ(context, ॱ(context, j), z);
        new DialogActivity.a(context, "WiFiHotspotDownloadDialog").ˎ(ॱ, null).ˋ(-1, n.ʼʻ).ˋ(-2, NetWorkUtil.getWifiResId(context, n.ʼʼ)).ˏ(aVar).ˋ(onDismissListener).ॱ(new d()).ˎ();
    }

    public static void ˊ(Context context, long j, a aVar, OnDismissListener onDismissListener, e eVar, OnKeyListener onKeyListener) {
        ˎ = 2;
        View ॱ = ॱ(context, ॱ(context, j), true);
        new DialogActivity.a(context, "WiFiHotspotDownloadDialog").ˎ(ॱ, null).ˋ(-1, n.ʼʻ).ˋ(-2, NetWorkUtil.getWifiResId(context, n.ʼʼ)).ˏ(aVar).ˋ(onDismissListener).ॱ(eVar).ˏ(onKeyListener).ˎ();
    }

    public static void ॱ(View view, boolean z) {
        Context ˋ = ContentManager.getInstant().getContext();
        if (view == null) {
            Logger.ˋ("DownloadDialogUtils", "downloadDialogView is null");
        } else if (doo.ʻ(ˋ)) {
            r0 = (CheckBox) view.findViewById(j.ᐝՙ);
            if (r0 != null) {
                ˏ(r0.isChecked(), z);
            }
        } else if (doo.ᐝ(ˋ)) {
            r0 = (CheckBox) view.findViewById(j.ˋˮ);
            if (r0 != null) {
                ˋ(r0.isChecked(), z);
            }
        } else {
            Logger.e("DownloadDialogUtils", "It will not be here forever");
        }
    }

    private static void ˏ(boolean z, boolean z2) {
        if (z && z2) {
            ehb.ˏ().ˋ(0);
        } else if (!z || z2) {
            ehb.ˏ().ˋ(1);
        } else {
            ehb.ˏ().ˋ(2);
        }
    }

    private static void ˋ(boolean z, boolean z2) {
        if (z && z2) {
            ehb.ˏ().ˋ(true);
        } else {
            ehb.ˏ().ˋ(false);
        }
    }
}
